/*
 * @Author: 李石
 * @Date: 2024-04-12 17:08:40
 * @LastEditors: lishi
 * @LastEditTime: 2024-07-16 11:40:18
 * @Description: 
 * Copyright (c) 2024 by ${lishi0105@163.com}, All Rights Reserved. 
 */
#ifndef _STREAM_PARSE_HPP_
#define _STREAM_PARSE_HPP_

#include <stdint.h>
#include <memory>
#include <mutex>
#include "NaluParse.h"
class StreamParse
{
public:
    using Ptr = std::shared_ptr<StreamParse>;
    static Ptr CreateShared(int32_t type);
    static Ptr CreateH264Shared();
    static Ptr CreateH265Shared();
    static Ptr CreateHEVCShared();
    ~StreamParse();
    bool parseStream(const void* data, size_t size);
    void getVideoInfo(videoinfo_t* videoinfo);
    int32_t width() const;
    int32_t height() const;
    float   fps() const;
    int32_t streamCodecId() ;
    std::string streamCodecName() ;
    void DebugSPS() ;
    void DebugPPS() ;
    void DebugVPS() ;
protected:
    StreamParse(int32_t type); // 0 -- h.264; 1 -- h.265
private:
    bool parseNALU(const uint8_t* data, size_t size, NALU_t* nalu);
private:
    h264_stream_t* m_hH264;
    h265_stream_t* m_hH265;
    int32_t m_nType; // 0:264 1:265
    int32_t pix_width;
    int32_t pix_height;
    mutable std::mutex mtx;
};

#endif // _STREAM_PARSE_HPP_